package com.base.caselib;

import android.view.View;

import com.alibaba.android.arouter.facade.annotation.Autowired;
import com.alibaba.android.arouter.facade.annotation.Route;
import com.base.caselib.databinding.ActivityAddcheckitemBinding;
import com.base.caselib.presenter.AddCheckItemPresenter;
import com.base.caselib.view.AddCheckItemView;
import com.base.commonlib.base.CBaseBarMvpActivity;
import com.base.commonlib.bean.CheckRecordEntity;
import com.base.commonlib.utils.RxBus2;

import java.util.UUID;

/**
 * 新增检查项
 * Created by weikailiang on 2019/11/14.
 */
@Route(path = "/addcheck/checkitem")
public class AddCheckItemActivity extends CBaseBarMvpActivity<AddCheckItemPresenter> implements AddCheckItemView{

    private ActivityAddcheckitemBinding mBinding;
    @Override
    protected int getLayoutResource() {
        return R.layout.activity_addcheckitem;
    }

    @Autowired(name = "mCheckRecord")
    CheckRecordEntity checkRecord;
    @Override
    protected void init() {
        super.init();
        mBinding = (ActivityAddcheckitemBinding) mRootBinding;
        mPresenter = new AddCheckItemPresenter(this,this);
        setBackNavigation();
        setBarTitle("新增检查项");
        setRigImg(R.drawable.ic_title_save, new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                CheckRecordEntity bean = mBinding.getEntity();
                if (bean.getLegislationId()==null){
                    bean.setLegislationId(UUID.randomUUID().toString());
                }
                if (mBinding.switchConfirm.isChecked()){
                    bean.setIsQualified(1);
                }else {
                    bean.setIsQualified(0);
                }
                if (mBinding.isMajor.isChecked()){
                    bean.setIsMajor(1);
                }else {
                    bean.setIsMajor(0);
                }
                RxBus2.getInstance().post(bean);
                finish();
            }
        });
        if (checkRecord!=null){
            mBinding.llMajor.setVisibility(View.VISIBLE);
            mBinding.setEntity(checkRecord);
            if (checkRecord.getIsQualified()!=null) {
                if (checkRecord.getIsQualified() == 1) {
                    mBinding.switchConfirm.setChecked(true);
                } else {
                    mBinding.switchConfirm.setChecked(false);
                }
            }else {
                mBinding.switchConfirm.setChecked(true);
            }
            if (checkRecord.getIsMajor()==1){
                mBinding.isMajor.setChecked(true);
            }else {
                mBinding.isMajor.setChecked(false);
            }
        }else {
            mBinding.llMajor.setVisibility(View.GONE);
            checkRecord = new CheckRecordEntity();
            checkRecord.setLawId("00010027");
            checkRecord.setLawName("其他");
            mBinding.setEntity(checkRecord);
        }


        mBinding.tvChoosePlate.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                showMes("待开放");
            }
        });
    }

    @Override
    protected void start() {

    }
}
